<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowe');

class Main extends CI_Controller {

    function __construct() { //inisialisasi library dan helper yang perlu di load
        parent::__construct();
        $this->load->helper('form');
        $this->load->helper('text');
        $this->load->library('pagination');
        $this->load->library('parser');
        $this->load->model('all');
    }

    function index() {//halaman utama
        $data['blog_title'] = 'SMP Negeri 1 Sanggau Ledo';
        $config['base_url'] = $this->config->config['base_url'] . '/index.php/main/index/';
        $config['total_rows'] = $this->all->get_berita();
        $config['per_page'] = 2;
        $config['num_links'] = 2;
        $config['full_tag_open'] = '<div class="pagination">';
        $config['full_tag_openclose'] = '</div>';
        $config['first_link'] = 'Awal';
        $config['first_tag_open'] = '<li>';
        $config['first_tag_close'] = '</li>';
        $config['cur_tag_open'] = '<li class="active"><a><strong>';
        $config['cur_tag_close'] = '</strong></a></li>';
        $config['last_link'] = 'Akhir';
        $config['last_tag_open'] = '<li>';
        $config['last_tag_close'] = '</li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
        $config['next_link'] = '&raquo;';
        $config['next_tag_open'] = '<li class="disable">';
        $config['next_tag_close'] = '</li>';
        $config['prev_link'] = '&laquo;';
        $config['prev_tag_open'] = '<li class="disable">';
        $config['prev_tag_close'] = '</li>';
        $config['uri'] = $this->uri->segment(3);
        $this->pagination->initialize($config);
        if ($this->all->berita($config)) {
            $data['berita'] = $this->all->berita($config);
        } else {
            $data['berita'] = array();
        }
        if ($this->all->slider()) {
            $data['slider'] = $this->all->slider();
        } else {
            $data['slider'] = array();
        }
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        $this->parser->parse('themes/head', $data);
        $this->load->view('themes/slider', $data);
        $this->load->view('themes/open_content');
        $this->load->view('themes/open_sidebar_left');
        $this->load->view('themes/sidebar_login');
        $this->load->view('themes/close_sidebar_left');
        $this->load->view('themes/open_sidebar_right');
        $this->load->view('themes/sidebar_right_content', $data);
        $this->load->view('themes/close_sidebar_right');
        $this->load->view('themes/close_content');
        $this->load->view('themes/footer');
    }

    function berita() {
        $data['blog_title'] = 'Berita | SMP Negeri 1 Sanggau Ledo';
        $data['slider'] = $this->all->slider();
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        $id = $this->uri->segment(3);
        if ($this->all->berita_id($id)) {
            $data['berita'] = $this->all->berita_id($id);
        } else {
            $data['berita'] = array();
        }
        $this->parser->parse('themes/head', $data);
        $this->load->view('themes/slider', $data);
        $this->load->view('themes/open_content');
        $this->load->view('themes/open_sidebar_left');
        $this->load->view('themes/sidebar_login');
        $this->load->view('themes/close_sidebar_left');
        $this->load->view('themes/open_sidebar_right');
        $this->load->view('themes/berita', $data);
        $this->load->view('themes/close_sidebar_right');
        $this->load->view('themes/close_content');
        $this->load->view('themes/footer');
    }

    function login() {
        $log = array(
            'id' => $this->input->post('username'),
            'password' => $this->encrypt->sha1($this->input->post('password'))
        );
        $login = $this->all->login($log); //kirim ke database
        if ($login->akses_id == 1) {
            $ses = array(
                'id' => $login->id,
                'login' => TRUE,
                'hak_akses' => 1
            );
            $this->session->set_userdata($ses);
            redirect('admin');
        } elseif ($login->akses_id == 2) {
            $ses = array(
                'id' => $login->id,
                'username' => $login->nama,
                'login' => TRUE,
                'hak_akses' => 2
            );
            $this->session->set_userdata($ses);
            redirect('guru');
        } elseif ($login->akses_id == 3) {
            $ses = array(
                'id' => $login->id,
                'username' => $login->nama,
                'login' => TRUE,
                'hak_akses' => 3
            );
            $this->session->set_userdata($ses);
            redirect('siswa');
        } else {
            redirect();
        }
    }

    function sejarah() {
        $data['blog_title'] = 'Sejarah | SMP Negeri 1 Sanggau Ledo';
        $data['slider'] = $this->all->slider();
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        if ($this->all->sejarah()) {
            $data['sejarah'] = $this->all->sejarah();
        } else {
            $data['sejarah'] = array();
        }
        $this->parser->parse('themes/head', $data);
        $this->load->view('themes/slider', $data);
        $this->load->view('themes/open_content');
        $this->load->view('themes/open_sidebar_left');
        $this->load->view('themes/sidebar_login');
        $this->load->view('themes/close_sidebar_left');
        $this->load->view('themes/open_sidebar_right');
        $this->load->view('themes/sejarah', $data);
        $this->load->view('themes/close_sidebar_right');
        $this->load->view('themes/close_content');
        $this->load->view('themes/footer');
    }

    function prasarana() {
        $data['blog_title'] = 'Prasarana | SMP Negeri 1 Sanggau Ledo';
        $data['slider'] = $this->all->slider();
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        if ($this->all->prasarana()) {
            $data['prasarana'] = $this->all->prasarana();
        } else {
            $data['prasarana'] = array();
        }
        $this->parser->parse('themes/head', $data);
        $this->load->view('themes/slider', $data);
        $this->load->view('themes/open_content');
        $this->load->view('themes/open_sidebar_left');
        $this->load->view('themes/sidebar_login');
        $this->load->view('themes/close_sidebar_left');
        $this->load->view('themes/open_sidebar_right');
        $this->load->view('themes/prasarana', $data);
        $this->load->view('themes/close_sidebar_right');
        $this->load->view('themes/close_content');
        $this->load->view('themes/footer');
    }

    function visi() {
        $data['blog_title'] = 'Visi dan Misi | SMP Negeri 1 Sanggau Ledo';
        $data['slider'] = $this->all->slider();
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        if ($this->all->visi()) {
            $data['visi'] = $this->all->visi();
        } else {
            $data['visi'] = array();
        }
        $this->parser->parse('themes/head', $data);
        $this->load->view('themes/slider', $data);
        $this->load->view('themes/open_content');
        $this->load->view('themes/open_sidebar_left');
        $this->load->view('themes/sidebar_login');
        $this->load->view('themes/close_sidebar_left');
        $this->load->view('themes/open_sidebar_right');
        $this->load->view('themes/visi', $data);
        $this->load->view('themes/close_sidebar_right');
        $this->load->view('themes/close_content');
        $this->load->view('themes/footer');
    }

    function pagenotfound() {
        $this->load->view('welcome_message');
    }

}